<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * View helper for authentication purposes
 *
 * @package RedCross_View_Helper
 * @category RedCross
 */
class RedCross_View_Helper_AuthInfo extends Zend_View_Helper_Abstract {

	private $_isLoggedIn;

	private $_authService;
	private $_user;

	public function __construct()
	{
		$this->_authService = RedCross_Factory::getService('Core_Service_Auth');
		$this->_user = $this->_authService->getIdentity();
	}

	public function authInfo()
	{
        return $this;
	}

	/**
	 * @deprecated
	 */
	public function isLoggedIn() {
		return $this->_authService->isAuthenticated();
	}

	public function isAuthenticated() {
		return $this->_authService->isAuthenticated();
	}

	public function getUsername() {
		if ($this->_authService->isAuthenticated()) {
			return $this->_user->username;
		}
	}

	public function getName()
	{
		if ($this->isLoggedIn())
		{
			return $this->_user->Member['first_name'] . ' ' . $this->_user->Member['last_name'];
		}
	}

	public function getMemberId()
	{
		if ($this->isLoggedIn())
		{
			return (int)$this->_user->Member['id'];
		}
	}
}
